package org.example.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.springboot.entity.User;

import java.util.List;
import java.util.Map;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 获取最近7天的用户活跃度数据
     * @return 每天的活跃用户数
     */
    @Select("SELECT DATE_FORMAT(ub.create_time, '%Y-%m-%d') AS day, COUNT(DISTINCT ub.user_id) AS count " +
            "FROM user_behavior ub " +
            "WHERE ub.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) " +
            "GROUP BY day " +
            "ORDER BY day ASC")
    List<Map<String, Object>> selectUserActivity();
}
